<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('选择机构')" />
    <link rel="stylesheet" th:href="@{/js/layuiadmin-1.2.1/style/dtree/dtree.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/js/layuiadmin-1.2.1/style/dtree/font/dtreefont.css}" media="all">
</head>
<body>
<div style="padding: 0 10px;">
	<div id="dhtree" class="demo-tree demo-tree-box"></div>
</div>
<th:block th:include="include :: footer" />
<script th:src="@{/dhecp/js/left-tree.js?v=1}"></script>
<script th:inline="javascript">
	/*<![CDATA[*/
	var vOrgs = [[${vOrgs}]];
	/*]]>*/
</script>
<script type="text/javascript">
	var dtree,layer;
	layui.extend({
        dtree : '/js/layuiadmin-1.2.1/lib/extend/dtree'
    }).use(['table','form','layer','jquery', 'util','dtree'], function () {
        dtree = layui.dtree;
        var treeData = getTree('/system/organization/listtreeselectjson?vOrgs='+vOrgs);
        CommonTreet = dtree.render({
            elem: "#dhtree",
//             menubar:true,
            record:true,
            width:"auto",
            data: treeData,
            checkbar: true,  
            checkbarType: "no-all",
            checkbarData: "halfChoose" 
        });
     // 绑定节点点击事件
		dtree.on("node(dhtree)", function(obj){
        	var nodeId = obj.param.nodeId;
        	CommonTreet.clickNodeCheckbar(nodeId);// 点击节点选中复选框
        	/* var checkbarNodes = dtree.getCheckbarNodesParam("dhtree");
        	$.each(checkbarNodes,function(i,v){
        		console.log(v.recordData.orgPath);
        	}) */
        });
    })
    var callbackdata = function () {
    	var checkbarNodes = dtree.getCheckbarNodesParam("dhtree");
    	//level级别排序1~9
    	checkbarNodes.sort(function(a,b){
            if(a.level>b.level) return 1 ;
            if(a.level<b.level) return -1 ;
            return 0 ;
     	}) ;
    	var orgnationObj =  [];
    	$.each(checkbarNodes,function(i,v){
    		if(v.checked == 1){orgnationObj.push(v);}
    	})
    	var returnObj = [];
    	$.each(orgnationObj,function(i,v){
    		var exit = true;
    		$.each(orgnationObj,function(i2,v2){
    			if(v.parentId == v2.nodeId){
   	    			exit = false;return false; }
    		})
    		if(exit == true)returnObj.push(v);
    	})
    	console.log(returnObj)
    	return returnObj;
    }
</script>
</body>
</html>